

clear 
use "$path\Intermediary Data\p_minus_pstar\petoile_0_200_psychologicalprices_logregression.dta"

forvalues i=400 (200) 3200 {
local j=`i'-200
append using "$path\Intermediary Data\p_minus_pstar\petoile_`j'_`i'_psychologicalprices_logregression.dta"

}


bysort daten: egen log_petoile_bis=mean(log_prix_ht)


******** V-shaped graph *****

bysort id (daten) : gen pht_moins_petoile_temp=log_prix_ht[_n-1] - log_petoile_bis
bysort id: egen mean_tc_moins_petoile=mean(pht_moins_petoile_temp)
gen pht_moins_petoile=pht_moins_petoile_temp-mean_tc_moins_petoile
replace pht_moins_petoile=pht_moins_petoile*100


bysort id (daten): gen forward_change=(prix[_n]-prix[_n-1]!=0)
bysort id (daten): gen positive_change=(prix[_n]-prix[_n-1]>0)
bysort id (daten): gen negative_change=(prix[_n]-prix[_n-1]<0)

capture drop log_price*
bysort id (daten): gen log_priceht_change=log_prix_ht[_n]-log_prix_ht[_n-1]
bysort id (daten): gen log_price_change=log(prix[_n])-log(prix[_n-1])
replace log_priceht_change=. if log_price_change==0
replace log_priceht_change=log_priceht_change*100

gen pos_log_priceht_change=log_priceht_change
replace pos_log_priceht_change=. if pos_log_priceht_change<0

gen neg_log_priceht_change=log_priceht_change
replace neg_log_priceht_change=. if neg_log_priceht_change>0

xtile xt_pht_moins_petoile=pht_moins_petoile if abs(pht_moins_petoile)<5, nq(100)
bysort  xt_pht_moins_petoile: gen first_obs_quantile=1 if _n==1
bysort  xt_pht_moins_petoile: egen mean_forward_change=mean(forward_change)
bysort  xt_pht_moins_petoile: egen mean_positive_change=mean(positive_change)
bysort  xt_pht_moins_petoile: egen mean_negative_change=mean(negative_change)
bysort  xt_pht_moins_petoile: egen mean_pht_moins_petoile=mean(pht_moins_petoile)




graph twoway (histogram pht_moins_petoile if abs(pht_moins_petoile)<5, density yaxis(1) col(gs10%50) yscale(range(0(0.05)0.25) axis(1)) ylabel(0(0.05)0.25,axis(1)) xlabel(-5(2.5)5,axis(1))) ///
(scatter mean_positive_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(gs8) yaxis(2) yscale(range(0(0.08)0.4) axis(2)) ylabel(0(0.08)0.4,axis(2)))  ///
(scatter mean_negative_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(black)  ///
yaxis(2) yscale(range(0(0.08)0.4) axis(2)) ylabel(0(0.08)0.4,axis(2)) graphregion(color(white)) ///
legend(order(1 "Density (Left axis) " 2 "Probability of positive price change (Right axis)" 3 "Probability of negative price change (Right axis)") cols(1)) xtitle("p-p* (in %)") ytitle("", axis(2)) ytitle("", axis(1)))
graph export "$path\Graphs_Tables\FigureA5a.png", replace



* Closing the gap

bysort  xt_pht_moins_petoile: egen mean_pos_log_priceht_change=mean(pos_log_priceht_change)
bysort  xt_pht_moins_petoile: egen mean_neg_log_priceht_change=mean(neg_log_priceht_change)
bysort  xt_pht_moins_petoile: egen mean_nonzero_log_priceht_change=mean(log_priceht_change)

replace mean_neg_log_priceht_change=-mean_neg_log_priceht_change

graph twoway (scatter mean_nonzero_log_priceht_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., xlabel(-5(2.5)5,axis(1)) col(black)  graphregion(color(white)) ///
legend(order(1 "Non-zero price changes") cols(1)) xtitle("p-p* (in %)") ytitle("Non-zero price variations (in %)"))
graph export "$path\Graphs_Tables\FigureA5b.png", replace
graph export "$path\Graphs_Tables\FigureA5b.eps", replace


graph twoway (scatter mean_neg_log_priceht_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., xlabel(-5(2.5)5,axis(1)) col(gs10)  graphregion(color(white))) ///
(scatter mean_pos_log_priceht_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(black)  graphregion(color(white)) ///
legend(order(1 "Minus negative price changes" 2 "Positive price changes") cols(1)) xtitle("p-p* (in %)") ytitle("Non-zero price variations (in %)"))
graph export "$path\Graphs_Tables\FigureA5c.png", replace
graph export "$path\Graphs_Tables\FigureA5c.eps", replace

